package  
{
	import org.flixel.*;
	
	public class HeartTombstone extends FlxSprite
	{
		public var colorShirtIndex:int = 0;
		private var _tombstoneHUD:TombstoneHUD = null;
		private var _myText:FlxText = null;
		private var _numberOfHearts:int = 0;
		
		public function HeartTombstone(tombstoneHUD:TombstoneHUD, ColorShirtIndex:int) 
		{
			_tombstoneHUD = tombstoneHUD;
			colorShirtIndex = ColorShirtIndex;
			loadGraphic(AssetManager.Heart);
			color = ConfigData.AVAILABLE_HEART_COLORS[colorShirtIndex];
			_myText = new FlxText(0, 0, 22, String(_numberOfHearts));
			_myText.scrollFactor = new FlxPoint(0, 0);
			_myText.color = ConfigData.AVAILABLE_HEART_COLORS[colorShirtIndex];
			_tombstoneHUD.add(_myText);
			
		}
		public function setX(_x:int):void
		{
			x = _x;
			_myText.x = _x + this.frameWidth / 2.0 + ConfigData.HUD_TEXT_OFFSETS[_myText.text.length];
		}
		
		public function setY(_y:int):void
		{
			y = _y;
			_myText.y = _y + this.frameHeight - _myText.frameHeight + 2;
		}
		
		public function turnToTombstone():void 
		{
			loadGraphic(AssetManager.TombstoneLarge);
			color = 0xFFFFFFFF;
			_tombstoneHUD.remove(_myText, true);
			_tombstoneHUD.add(_myText);
		}
		
		public function addHeart():void 
		{
			_numberOfHearts++;
			var oldLength:int = _myText.text.length;
			_myText.text = String(_numberOfHearts);
			var newLength:int = _myText.text.length;
			if (newLength != oldLength)
			{
				// remove previous offset
				_myText.x -= ConfigData.HUD_TEXT_OFFSETS[oldLength];
				// apply new offset
				_myText.x += ConfigData.HUD_TEXT_OFFSETS[newLength];
			}
		}
		
	}

}